import matplotlib.pyplot as plt
import numpy as np


def draw_anchors(anchors, SIZE_LEN):
    anchors /= 13.
    anchors *= SIZE_LEN

    w = anchors[:, 0]
    h = anchors[:, 1]
    x1 = SIZE_LEN / 2 - w / 2
    y1 = SIZE_LEN / 2 - h / 2
    x2 = SIZE_LEN / 2 + w / 2
    y2 = SIZE_LEN / 2 + h / 2

    plt.plot([x1, x2], [y1, y1])
    plt.plot([x1, x2], [y2, y2])
    plt.plot([x1, x1], [y1, y2])
    plt.plot([x2, x2], [y1, y2])

    for i, [x1i, y1i] in enumerate(zip(x1, y1)):
        plt.annotate(f'#{i}', xy=[x1i, y1i])

    plt.xlim(0, 416)
    plt.ylim(0, 416)
    plt.ylim(plt.ylim()[::-1])


if '__main__' == __name__:
    plt.figure(figsize=[12, 6])
    spr = 1
    spc = 2
    spn = 0

    SIZE_LEN = 416
    anchors = np.array([[0.57273, 0.677385],
               [1.87446, 2.06253],
               [3.33843, 5.47434],
               [7.88282, 3.52778],
               [9.77052, 9.16828]])

    spn += 1
    plt.subplot(spr, spc, spn)
    plt.title('COCO')
    draw_anchors(anchors, SIZE_LEN)

    anchors = np.array(
        [(1.3221, 1.73145), (3.19275, 4.00944), (5.05587, 8.09892), (9.47112, 4.84053), (11.2364, 10.0071)])

    spn += 1
    plt.subplot(spr, spc, spn)
    plt.title('VOC')
    draw_anchors(anchors, SIZE_LEN)

    plt.show()
